package le.cn.bio.client;

import cn.le.util.InputUtil;
import cn.le.util.info.HostInfo;

import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

public class BIOEchoClient {

    public static void main(String[] args) throws IOException {
        Socket client = new Socket(HostInfo.HOST_NAME,HostInfo.PORT);
        Scanner scanner = new Scanner(client.getInputStream());
        scanner.useDelimiter("\n");
        PrintStream out = new PrintStream(client.getOutputStream());
        boolean flag = true;
        while (flag){
            String inputData = InputUtil.getString("请出入内容:").trim();
            out.println(inputData); //把数据发送到服务器上
            if (scanner.hasNext()){
                String str = scanner.next().trim();
                System.out.println(str);
            }
            if ("byebye".equalsIgnoreCase(inputData)){
                flag = false;
            }
        }
        client.close();
    }

}
